const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        
             radioItems2:[{"checked":true,"label":"男","value":"男"},{"checked":false,"label":"女","value":"女"}],

        buttons3: [{
            type: 'submit',
            url: App.renderUrl('empty', 'index'),
            title: ``
        }],
        users: [] //存放用户信息

    },

   //弹出提示信息
    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function() {},

    //页面加载
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option
            })
        }

        this.getForm1();
        this.chushi();
    },

   //页面显示
    onShow() {

    },

    //设置输入验证
    getForm1() {
        this.WxValidate = App.WxValidate({
           mname: {
		required:{
			message:'姓名：不能为空哟'
		}
	},
tel: {
		tel:{
			message:'手机号码：请输入11位的手机号码'
		},
		required:{
			message:'手机号码：不能为空哟'
		}
	},
card: {
		required:{
			message:'身份证号：不能为空哟'
		}
	},
address: {
		required:{
			message:'联系地址：不能为空哟'
		}
	},

        })
    },

    //修改
    formSubmit1: function(e) {
        if (!this.WxValidate.checkForm(e)) { //输入验证不通过时，弹出相应的提示信息，并返回
            const error = this.WxValidate.errorList[0]
            var msg = `${error.msg}`;
            this.showModal(msg);
            return false
        } else {
            var data = e.detail.value;

            data = App.Tools.extend(data, {
                f: 1,
                id: wx.getStorageSync("mid")
            });

            App.HttpService.saveData(data, "/members_Edit").then(data => { //执行服务器Servlet，并根据返回值，弹出相应的提示
                App.WxService.showToast({
                    title: "修改成功!",
                    icon: 'success',
                    duration: 1500,
                });
                setTimeout(function() {
                    wx.navigateBack(); //返回上页
                }, 1500)
            });
        }
    },
    formReset1: function() {
        console.log('form发生了reset事件')
    },
    changesex: function(value) {
    if (value.detail) {
        value = value.detail.value
    }
    var radioItems2 = this.data.radioItems2;
    for (var i = 0, len = radioItems2.length; i < len; ++i) {
        radioItems2[i].checked = radioItems2[i].value == value;
    }
    this.setData({
        radioItems2: radioItems2
    });
},

    

    //初始化用户信息
    chushi() {
        //设置要传递的参数
        let param = {
            f: 1,
            mid: wx.getStorageSync("mid"),
            loadmsg: `正在加载中`
        };


        App.HttpService.getData(param, "/members_List").then(data => { //执行服务器Servlet


            this.setData({
                
                users: data  //把从服务器端得到的值赋值给数组
            });
            this.changesex(data[0].sex);
        });
    },

    onChangeAddress: function () {
        var _page = this;
        wx.chooseLocation({
            success: function (res) {
                console.log(res);
                _page.setData({
                    address: res.address
                });
            },
            fail: function (err) {
                console.log(err)
            }
        });
    },


})
